package org.luu.medicare.controller.medicareInfoController;

import lombok.Generated;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.luu.medicare.common.Result;
import org.luu.medicare.entity.PageBean;
import org.luu.medicare.entity.TMedicine;
import org.luu.medicare.service.MedicineInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/medicine")
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class MedicineInfoController {
    private final MedicineInfoService medicineInfoService;

    @GetMapping
    public Result<PageBean<TMedicine>> page(@RequestParam(defaultValue = "1") int page,
                                            @RequestParam(defaultValue = "10") int pageSize,
                                            String name,
                                            String id){
        log.info("药品 page:{},pageSize:{},name:{},id:{}",page,pageSize,name,id);
        return medicineInfoService.page(page,pageSize,name,id);
    }

    @GetMapping("/{id}")
    public Result<TMedicine> findById(@PathVariable Integer id){
        log.info("药品 findById:{}",id);
        return medicineInfoService.findById(id);
    }

    @DeleteMapping("/{id}")
    public Result<String> deleteById(@PathVariable Integer id){
        log.info("药品 deleteById:{}",id);
        return medicineInfoService.deleteById(id);
    }

    @PostMapping
    public Result<String> save(@RequestBody TMedicine medicine){
        log.info("药品 save:{}",medicine);
        return medicineInfoService.save(medicine);
    }

    @PutMapping
    public Result<String> update(@RequestBody TMedicine medicine){
        log.info("药品 update:{}",medicine);
        return medicineInfoService.update(medicine);
    }
}
